<template>
    <view class="container">
		<view class="order-title" v-if="!signStatus">
			<input type="number" maxlength="11" placeholder="请输入您的有效联系方式" v-model="phone">
		</view>
		<view class="order-title">
			<input type="number" placeholder="请输入验证码" maxlength="6" v-model="codeMsg">
			<view class="code" @click="gotCode">{{codeStatus}}</view>
		</view>
		<view class="g-btn">
			<view class="btn" @click="save">保存</view>
		</view>
    </view>
</template>
<script>
import {_msgCode,_bindPhone} from '../../common/vmeitime-http/mem.js';
import {_updatePhone} from '../../common/vmeitime-http/user.js'

export default {
    data() {
        return {
            phone: "",
            codeMsg: "",
            signStatus: false,//认证状态,
            codeStatus: "获取验证码",
            codeTime: 120,
			mark:""
        }
    },
    onLoad(options) {
        this.mark = options.mark
    },
    methods: {
        async gotCode() {
            if (this.phone == "" || this.phone.length !== 11) {
                this.$api.msg("请输入正确的手机号")
                return false;
            }
            let t = null;
            let that = this;
            if (this.codeStatus == "获取验证码" || this.codeStatus == "重新发送") {
                let tempData = await _msgCode({phone: this.phone});
                if (tempData.data.code == 200) {
                    this.$api.msg("短信验证码发送成功，请注意查收！")
					this.codeMsg = ""
                } else {
                    return false;
                }
                t = setInterval(function () {
                    if (that.codeTime == 0) {
                        that.codeStatus = "重新发送";
                        that.codeTime = 120;
                        clearInterval(t);
                        return false
                    }
                    that.codeStatus = "重新发送 " + that.codeTime--;
                }, 1000)
            }
        },
		
		
		
		save(){
			if (this.codeMsg == "") {
				this.$api.msg("请填写短信验证码");
				return false
			}
			_updatePhone({phone:this.phone,code:this.codeMsg}).then(res =>{
				console.log(res)
				var info = uni.getStorageSync("userInfo")
				info.tel = this.phone
				uni.setStorageSync("userInfo",info)
				uni.navigateBack()
			})
		}
		
		
		
    //     async save() {
    //         if (this.codeMsg == "") {
    //             this.$api.msg("请填写短信验证码");
    //             return false
    //         }
    //         let para = {
    //             telephone: this.phone,
    //             authCode: this.codeMsg
    //         };
    //         let tempData = await _bindPhone(para)
    //         if (tempData.data.code == 200) {
    //             this.$api.msg("绑定手机号成功！");
    //             if(this.mark == "loginBind"){
    //                 let tempDataD = await _userInfo();
    //                 if(tempDataD.data.code == 200){
    //                     uni.setStorageSync('relUserInfo',tempDataD.data.data);
    //                     setTimeout(()=>{
    //                         uni.switchTab({
    //                             url: '/pages/index/index'
    //                         });
				// 		},800)
    //                 }
				// }else{
    //                 this.$api.prePage().refreshPhone(this.phone);
    //                 setTimeout(() => {
    //                     uni.navigateBack()
    //                 }, 800)
				// }
    //         }
    //     }
    }
}

</script>
<style lang='scss'>
	page{
		background: #F2F2F2;
	}
	.order-title{
		margin-top: 10upx;
		display: flex;
		padding: 30upx;
		background: #ffffff;
		border-bottom: 2upx solid #f2f2f2;
		align-items: center;
		input{
			font-size: 26upx;
			width: 420upx;

		}
		.code{
			display: flex;
			flex:1;
			justify-content: center;
			font-size: 26upx;
			color: $uni-color-primary;
			border-left:2upx solid #f2f2f2;
		}
	}
	.g-btn{
		position: absolute;
		width: 100%;
		bottom: 20upx;
		.btn{
			width: 690upx;
			color: #ffffff;
			background: $uni-color-primary;
			text-align: center;
			padding: 20upx 0;
			border-radius: 16upx;
			font-size: 32upx;
			margin: auto;
		}
	}
</style>